package com.md.model.html;

import com.md.value.html.LabelStyleType;
import com.md.value.html.Unit;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Optional;

/**
 * @author 刘骄阳
 * 2024-05-15 23:44
 */
@Getter
@AllArgsConstructor(staticName = "of")
public final class LabelStyle {
  private final LabelStyleType styleType;
  private final Object value;
  private final Unit unit;

  public static LabelStyle of(final LabelStyleType styleType, final Object value) {
    return new LabelStyle(styleType, value, null);
  }

  public String getStyleCode() {
    return String.format("%s:%s%s;",
      styleType.getStyleName(), value, Optional.ofNullable(unit).map(Unit::getValue).orElse(""));
  }

  public String getUnitValue() {
    return Optional.ofNullable(unit).map(Unit::getValue).orElse("");
  }

  public String getStyleName() {
    return styleType.getStyleName();
  }
}
